<template>
    <div class="reg">
        <van-nav-bar title="注册" left-arrow class="header" @click-left="goBack"></van-nav-bar>
        <van-form >
            <!-- 用户名 -->
            <van-field v-model="nickname" name="用户名" label="用户名" placeholder="用户名"
                :rules="[{ required: true, message: '请填写用户名' }]" />

            <!-- 账户名 -->
            <van-field v-model="username" name="账户名" label="账户名" placeholder="账户名"
                :rules="[{ required: true, message: '请填写账户名' }]" />

            <!-- 密码 -->
            <van-field v-model="password1" type="password" label="密码" placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]" />

            <!-- 重新输入密码 -->
            <van-field v-model="password2" type="password" label="重新输入密码" placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]" />

           
            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit" @click="goReg">注册</van-button>
            </div>
        </van-form>
    </div>
</template>

<script>
  
export default {
    data() {
        return {
            nickname:'',
            username: "",
            password1: "",
            password2: "",
        }
    },
   
    methods: {
        goBack() {
            this.$router.back();
        },

       
        // 注册

        goReg() {
            console.log('我在点击注册');
            event.preventDefault();
            if(this.nickname.trim()!=''&&this.password1.trim()!=''&&this.password2.trim()!=''){
                if(this.password1===this.password2){
                    console.log("对了");
                    this.$service({
                        url:"user/dofinishregister",
                        method:"post",
                        data:`tel=${this.username}&password=${this.password1}`
                    }).then(res=>{
                        console.log(res.data);
                    })

                }
                // console.log("成功了");
            }else{
                console.log("失败了");
            }
            // 发送注册请求
            // this.$service({
            //     method:"post",
            //     url:'user/dofinishregister',
            //     data:`tel=${this.username}&password=${this.password1}`
            // })
            // .then(res=>{
            //     console.log(res);
            //     if(res.data.code==200){
            //         console.log("res.data.message",res.data.message);
            //         this.$toast('注册成功')
            //        this.$cookie.set('nickname',this.nickname)
            //         this.$router.push('./login')
                  
            //     }
            // })
            // .catch(err=>{
            //     console.log("err.data.message",err);
            // })

        }
        
    },
}
</script>

<style scoped>
    .an-form{
        padding: 0 .625rem;
    }
</style>